var Adv_skd=require("./Adv_skd")
var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s,
    c,
    l,
    d = e("AssetsMap"),
    u = e("BundleNames"),
    p = e("Util"),
    h = e("GameData"),
    f = e("SkinLevelData"),
    _ = e("TaskData"),
    y = e("LoginProxy");
((l = s || (s = {})).daiji = "daiji"), (l.qidong = "qidong"), window.wx;
var m = cc._decorator,
    g = m.ccclass,
    v = m.property,
    w = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.btn_egg = null),
                (t.btn_coin = null),
                (t.btn_ad = null),
                (t.GetRewards_layer = null),
                (t.btn_free = null),
                (t.count_down = null),
                (t.mainEggAni = null),
                (t.times = [0, 2, 5, 10, 10]),
                (t.content = null),
                (t.isPlayAct = !1),
                (t.GetRewardIsCoin = !1),
                (t.GetRewardCount = 0),
                (t.GetRewardData = null),
                t
            );
        }
        return (
            a(t, e),
            (t.prototype.onLoad = function () {
                this.isCache = !1;
                Adv_skd.default.instance.hideAllAdv();
                Adv_skd.default.instance.showGridAdLeft();
                Adv_skd.default.instance.showInterstitialAd();
            }),
            (t.prototype.onResetView = function () {
                e.prototype.onResetView.call(this),
                    ad.curr_platform == window.ad.Platform.MEI_ZU && ad.adInterface.showInterstitial(),
                    ad.curr_platform == window.ad.Platform.HUAWEI_GAME && ad.adInterface.showNativeInterstitial(),
                    ad.curr_platform == window.ad.Platform.BAI_DU && ad.adInterface.showBanner(),
                    this.init(),
                    this.renderFreeEgg();
            }),
            (t.prototype.onClickClose = function () {
                Adv_skd.default.instance.hideAllAdv();

                Adv_skd.default.instance.showGridAdLeftOne();
                Adv_skd.default.instance.showGridAdRightOne();
                Adv_skd.default.instance.showInterstitialAd();

                game.AudioManager.playBtnEffect(), this.closeView(!0);
            }),
            (t.prototype.renderFreeEgg = function () {
                var e = game.appFacade.retrieveProxy(y.default.NAME).getEggInfo();
                if (e.num >= 4)
                    this.btnFreeRender(!1), (this.count_down.getComponent(cc.Label).string = "明日登录可免费扭5次");
                else if (0 === e.num)
                    this.btnFreeRender(!0),
                        (this.count_down.getComponent(cc.Label).string = "今日还有" + (5 - e.num) + "次免费机会");
                else {
                    var t = 6e4 * this.times[e.num],
                        o = e.time + t;
                    new Date().getTime() >= o
                        ? (this.btnFreeRender(!0),
                          (this.count_down.getComponent(cc.Label).string = "今日还有" + (5 - e.num) + "次免费机会"))
                        : (this.btnFreeRender(!1), this.unschedule(this.countDown), this.schedule(this.countDown, 1));
                }
            }),
            (t.prototype.btnFreeRender = function (e) {
                (this.btn_free.getComponent(cc.Button).interactable = e),
                    p.default.updateMaterialState(this.btn_free, !e);
            }),
            (t.prototype.clickFreeEgg = function () {
                if (!this.isPlayAct) {
                    var e = game.appFacade.retrieveProxy(y.default.NAME),
                        t = e.getEggInfo();
                    if (t.num >= 4) game.UIManager.instance.showToast("今日免费次数已达到上限");
                    else {
                        var o = ad.curr_platform === window.ad.Platform.TOU_TIAO;
                        if (
                            (game.log("T=> 免费扭蛋"),
                            o && window.tt.reportAnalytics("NiuDan_MianFei", {}),
                            0 === t.num)
                        )
                            return this.onOpenEgg(), e.setEggInfo(), void this.renderFreeEgg();
                        var n = 6e4 * this.times[t.num],
                            i = t.time + n;
                        new Date().getTime() >= i
                            ? (this.onOpenEgg(), e.setEggInfo(), this.renderFreeEgg())
                            : game.UIManager.instance.showToast("倒计时未结束");
                    }
                }
            }),
            (t.prototype.countDown = function () {
                var e = game.appFacade.retrieveProxy(y.default.NAME).getEggInfo(),
                    t = 6e4 * this.times[e.num],
                    o = (e.time + t - new Date().getTime()) / 1e3;
                o <= 0 && (this.btnFreeRender(!0), this.unschedule(this.countDown), (o = 0)),
                    (this.count_down.getComponent(cc.Label).string = p.default.countDownPase(o) + "后可免费扭一次");
            }),
            (t.prototype.onDisable = function () {
                ad.curr_platform == window.ad.Platform.BAI_DU && ad.adInterface.hideBanner(!1),
                    ad.curr_platform == window.ad.Platform.OPPO && ad.adInterface.hideNativeBanner(!1);
            }),
            (t.prototype.onEnable = function () {}),
            (t.prototype.registerMediator = function () {
                e.prototype.registerMediator.call(this);
            }),
            (t.prototype.removeMediator = function () {
                e.prototype.removeMediator.call(this);
            }),
            (t.prototype.addEvent = function () {
                e.prototype.addEvent.call(this),
                    this.btn_egg.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_egg, this),
                    this.btn_coin.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_coin, this),
                    this.btn_ad.on(game.EngineEventType.NodeEvent.click, this.onClick_btn_ad, this),
                    this.btn_free.on(game.EngineEventType.NodeEvent.click, this.clickFreeEgg, this),
                    this.GetRewards_layer.getChildByName("btn_getDouble").on(
                        game.EngineEventType.NodeEvent.click,
                        this.onClickbtn_getDouble,
                        this
                    ),
                    this.GetRewards_layer.getChildByName("btn_getRewards").on(
                        game.EngineEventType.NodeEvent.click,
                        this.onClickbtn_getRewards,
                        this
                    ),
                    this.GetRewards_layer.getChildByName("tt_btn_getRewards").on(
                        game.EngineEventType.NodeEvent.click,
                        this.onClickbtn_getRewards,
                        this
                    );
            }),
            (t.prototype.removeEvent = function () {
                e.prototype.removeEvent.call(this),
                    this.btn_egg.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_egg, this),
                    this.btn_coin.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_coin, this),
                    this.btn_ad.off(game.EngineEventType.NodeEvent.click, this.onClick_btn_ad, this),
                    this.btn_free.off(game.EngineEventType.NodeEvent.click, this.clickFreeEgg, this),
                    this.GetRewards_layer.getChildByName("btn_getDouble").off(
                        game.EngineEventType.NodeEvent.click,
                        this.onClickbtn_getDouble,
                        this
                    ),
                    this.GetRewards_layer.getChildByName("btn_getRewards").off(
                        game.EngineEventType.NodeEvent.click,
                        this.onClickbtn_getRewards,
                        this
                    ),
                    this.GetRewards_layer.getChildByName("tt_btn_getRewards").off(
                        game.EngineEventType.NodeEvent.click,
                        this.onClickbtn_getRewards,
                        this
                    );
            }),
            (t.prototype.onClick_btn_egg = function () {
                if (!this.isPlayAct) {
                    if (h.default.instance.getPlayerEgg() <= 0) return game.UIManager.instance.showToast("扭蛋不足");
                    var e = h.default.instance.getPlayerEgg();
                    h.default.instance.setPlayerEgg(e - 1), this.refreshEggCount(), this.onOpenEgg();
                }
            }),
            (t.prototype.onClick_btn_coin = function () {
                if (!this.isPlayAct) {
                    var e = h.default.instance.getPlayerCoin();
                    if (e < 2e3) return game.UIManager.instance.showToast("钻石不足");
                    h.default.instance.setPlayerCoin(e - 2e3), this.onOpenEgg();
                }
            }),
            (t.prototype.onClick_btn_ad = function () {
                if (!this.isPlayAct) {
                    var e = ad.curr_platform === window.ad.Platform.TOU_TIAO;
                    game.log("T=> 视频扭蛋"),
                        e && window.tt.reportAnalytics("NiuDan_ShiPin", {}),
                        ad.adInterface.showRewardedVideo(null, null, function () {
                            c.onOpenEgg();
                        });
                }
            }),
            (t.prototype.onOpenEgg = function () {
                game.AudioManager.playBtnEffect(),
                    _.default.instance.collectPlayerEggData(),
                    (this.isPlayAct = !0),
                    this.mainEggAni.removeEventListener(
                        dragonBones.EventObject.COMPLETE,
                        this.playAnimationFinish,
                        this
                    ),
                    this.mainEggAni.addEventListener(dragonBones.EventObject.COMPLETE, this.playAnimationFinish, this),
                    this.mainEggAni.playAnimation(s.qidong, 1);
            }),
            (t.prototype.init = function () {
                (c = this),
                    (this.isCache = !1),
                    (this.content = this.node.getChildByName("content")),
                    this.refreshEggCount(),
                    this.mainEggAni.playAnimation(s.daiji, -1),
                    ad.curr_platform == window.ad.Platform.TOU_TIAO
                        ? ((this.GetRewards_layer.getChildByName("btn_getRewards").active = !1),
                          (this.GetRewards_layer.getChildByName("tt_btn_getRewards").active = !0),
                          this.GetRewards_layer.getChildByName("btn_getDouble").setPosition(cc.v3(180, -200, 0)),
                          this.GetRewards_layer.getChildByName("tt_btn_getRewards").setPosition(cc.v3(-180, -200, 0)))
                        : ad.curr_platform == window.ad.Platform.OPPO &&
                          ((this.GetRewards_layer.getChildByName("btn_getRewards").active = !1),
                          (this.GetRewards_layer.getChildByName("tt_btn_getRewards").active = !0),
                          this.GetRewards_layer.getChildByName("btn_getDouble").setPosition(cc.v3(180, -100, 0)),
                          this.GetRewards_layer.getChildByName("tt_btn_getRewards").setPosition(cc.v3(-180, -100, 0)));
            }),
            (t.prototype.refreshEggCount = function () {
                this.btn_egg.getChildByName("egg_num_tip").getComponent(cc.Label).string = h.default.instance
                    .getPlayerEgg()
                    .toString();
            }),
            (t.prototype.playAnimationFinish = function () {
                var e = this;
                this.mainEggAni.removeEventListener(dragonBones.EventObject.COMPLETE, this.playAnimationFinish, this),
                    this.mainEggAni.playAnimation(s.daiji, -1),
                    ad.curr_platform == window.ad.Platform.OPPO && ad.adInterface.showNativeBanner(),
                    ad.curr_platform != window.ad.Platform.OPPO &&
                        ad.curr_platform != window.ad.Platform.TOU_TIAO &&
                        ((this.GetRewards_layer.getChildByName("btn_getRewards").active = !1),
                        this.scheduleOnce(function () {
                            e.GetRewards_layer.getChildByName("btn_getRewards").active = !0;
                        }, 2)),
                    (this.isPlayAct = !1),
                    (this.GetRewards_layer.active = !0);
                var t = f.SkinLevelData.instance.skinList,
                    o = t[p.default.randomFrom(0, t.length - 1)];
                (this.GetRewardData = o),
                    (this.GetRewardCount = 5),
                    (this.GetRewards_layer.getChildByName("fragment_label").getComponent(cc.Label).string =
                        this.GetRewardData.chinese + "碎片*" + this.GetRewardCount);
                var n = "fragment_icon_" + this.GetRewardData.name,
                    i = game.BundleManager.instance
                        .getBundle(u.default.Popup)
                        .get(d.default.PopupMap.EggView.preAssets.textures.assetsList[n], cc.SpriteFrame);
                (this.GetRewards_layer.getChildByName("fragment_image").getComponent(cc.Sprite).spriteFrame = i),
                    (this.GetRewardIsCoin = p.default.randomFrom(1, 100) <= 10),
                    this.GetRewardIsCoin &&
                        ((this.GetRewardCount = p.default.randomFrom(5, 25)),
                        (this.GetRewards_layer.getChildByName("fragment_label").getComponent(cc.Label).string =
                            "钻石+" + this.GetRewardCount)),
                    (this.GetRewards_layer.getChildByName("fragment_image").active = !this.GetRewardIsCoin),
                    (this.GetRewards_layer.getChildByName("coin_image").active = this.GetRewardIsCoin);
            }),
            (t.prototype.onClickbtn_getDouble = function () {
                game.AudioManager.playBtnEffect(),
                    ad.adInterface.showRewardedVideo(null, null, function () {
                        if (
                            (ad.curr_platform == window.ad.Platform.OPPO && ad.adInterface.showNativeBanner(),
                            (c.GetRewards_layer.active = !1),
                            game.UIManager.instance.showToast("已双倍领取"),
                            c.GetRewardIsCoin)
                        ) {
                            var e = h.default.instance.getPlayerCoin();
                            h.default.instance.setPlayerCoin(e + 2 * c.GetRewardCount);
                        } else f.SkinLevelData.instance.add_fragments(c.GetRewardData, 10);
                    });
            }),
            (t.prototype.onClickbtn_getRewards = function () {
                if (
                    (game.AudioManager.playBtnEffect(),
                    (this.GetRewards_layer.active = !1),
                    ad.curr_platform == window.ad.Platform.OPPO && ad.adInterface.showNativeBanner(),
                    game.UIManager.instance.showToast("已领取"),
                    c.GetRewardIsCoin)
                ) {
                    var e = h.default.instance.getPlayerCoin();
                    h.default.instance.setPlayerCoin(e + this.GetRewardCount);
                } else f.SkinLevelData.instance.add_fragments(c.GetRewardData, 5);
            }),
            r([v(cc.Node)], t.prototype, "btn_egg", void 0),
            r([v(cc.Node)], t.prototype, "btn_coin", void 0),
            r([v(cc.Node)], t.prototype, "btn_ad", void 0),
            r([v(cc.Node)], t.prototype, "GetRewards_layer", void 0),
            r([v(cc.Node)], t.prototype, "btn_free", void 0),
            r([v(cc.Node)], t.prototype, "count_down", void 0),
            r([v(dragonBones.ArmatureDisplay)], t.prototype, "mainEggAni", void 0),
            r([g], t)
        );
    })(game.BasePopView);
i.default = w;
